package bsw.wode.service;

import bsw.wode.config.SessionConstant;
import bsw.wode.dao.UserDAO;
import bsw.wode.entity.WodeUser;

public class LoginService extends BaseService {
	
	@SuppressWarnings("unchecked")
	public boolean login(String loginName, String password)
	{
		//将原先登陆的用户注销
		session.put(SessionConstant.CUR_USER, null);
		
		UserDAO userDAO = (UserDAO)this.getDAO("UserDAO");
		WodeUser existUser = userDAO.findUserByLoginName(loginName);
		if(existUser == null)
		{
			return false;
		}
		
		if(!existUser.getPassword().equals(password))
		{
			return false;
		}
		
		//在Session中保存当前用户对象以标志用户登陆成功。
		session.put(SessionConstant.CUR_USER, existUser);
		return true;
	}
	
	@SuppressWarnings("unchecked")
	public boolean logout()
	{
		session.put(SessionConstant.CUR_USER, null);
		return true;
	}
	
	
	@SuppressWarnings("unchecked")
	public boolean resetPassword()
	{
		session.put(SessionConstant.CUR_USER, null);
		return true;
	}
	
}
